#include <map>
#include <iostream>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
// c 调用c++
extern "C"
{
    std::map<uint64_t, std::string> jobs_results_;
    std::map<uint64_t, std::string > jobs_results2_;
    std::map<uint64_t, char *> jobs_results3_;
    static char *CopyString(const std::string &str)
    {
        char *result = reinterpret_cast<char *>(malloc(sizeof(char) * str.size()));
        memcpy(result, str.data(), sizeof(char) * str.size());
        return result;
    }
    int generate_string(std::string *output)
    {
        output->append("gggggg");
    }
    int exec_string()
    {
        std::string cur_compaction_result;
        generate_string(&cur_compaction_result);
        jobs_results_.emplace(1, std::move(cur_compaction_result));
        return 0;
    }
    int exec_string2()
    {
        std::string cur_compaction_result1;
        generate_string(&cur_compaction_result1);
        std::string *s_result = new std::string(cur_compaction_result1, cur_compaction_result1.size());
        std::cout << "message " << s_result  <<" cur:"<< cur_compaction_result1 <<   std::endl;
        jobs_results2_.emplace(1, *s_result);
        return 0;
    }
    int exec_string3()
    {
        std::string cur_compaction_result1;
        generate_string(&cur_compaction_result1);
        std::string *s_result = new std::string(cur_compaction_result1, cur_compaction_result1.size());
        return 0;
    }
        char *get_string() {
            char *s;
        }

    char *get_string()
    {
        static char *s_result = nullptr;
        
        uint64_t job_id = 1;
        std::string cur_compaction_result;
        auto i = jobs_results_.find(job_id);
        if (i == jobs_results_.end())
        {
        }
        cur_compaction_result = i->second;
        std::cout << "message "<< cur_compaction_result << std::endl;
        s_result = CopyString(cur_compaction_result); // 踩内存
        printf("%s\n", s_result);
        return s_result;
    }
    char *get_string2()
    {
        char *s_result = nullptr;
        uint64_t job_id = 1;
        std::string cur_compaction_result;
        auto i = jobs_results2_.find(job_id);
        if (i == jobs_results2_.end())
        {
        }
        cur_compaction_result = i->second;
        std::cout << "message "<< cur_compaction_result << std::endl;
        s_result = CopyString(cur_compaction_result); // 踩内存
        printf("%s\n", s_result);
        return s_result;
    }
}
